﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;



public class ControllerPadCommandInteractive : MonoBehaviour {
    public VRControllerInteractive controllerInteractive;
    public Texture UpLeftSprite;
    public Texture UpRightSprite;
    public Texture DownLeftSprite;
    public Texture DownRihgtSprite;
    public Texture NoneSprite;

    public ControllerPadCommandState state;
    public bool pressed;

    private void Start()
    {
        controllerInteractive.ReleaseHolding += CleanUpCommandDisply;
    }

    private void Update()
    {
        state = ControllerPadCommandState.None;
        
        if (!controllerInteractive.isHolding) return;

        var commandDisplay = controllerInteractive.controller.GetComponent<CommandPadDisplay>();
        if (commandDisplay == null) return;
        pressed = commandDisplay.Pressed;
        state = commandDisplay.state;
        commandDisplay.ul.material.mainTexture = UpLeftSprite;
        commandDisplay.ur.material.mainTexture = UpRightSprite;
        commandDisplay.dl.material.mainTexture = DownLeftSprite;
        commandDisplay.dr.material.mainTexture = DownRihgtSprite;

    }

    public void CleanUpCommandDisply()
    {
        var commandDisplay = controllerInteractive.controller.GetComponent<CommandPadDisplay>();
        if (commandDisplay == null) return;
        commandDisplay.ul.material.mainTexture = NoneSprite;
        commandDisplay.ur.material.mainTexture = NoneSprite;
        commandDisplay.dl.material.mainTexture = NoneSprite;
        commandDisplay.dr.material.mainTexture = NoneSprite;
        commandDisplay = null;
    }

}
